﻿<?php
session_start();
/**
 * @author HIENDV
 * @copyright 2012
 */
include_once 'Model/Account.php';
//ini_set('display_errors',0); 
//error_reporting(0);
$user = $_REQUEST['username'];
$pass = $_REQUEST['password'];
$acc = new Account($user,$pass);
$rs= $acc->checkAccount();
//print_r($rs);
if($rs !=0){
    $_SESSION['username'] = $user;
	$_SESSION['first_name'] = $rs[0];
	$_SESSION['last_name'] = $rs[1];
	$_SESSION['level'] = $rs[2];
	$_SESSION['account_type'] = $rs[3];
	$_SESSION['password'] = $pass;
	echo '1';
	$file='../log/debug/'.date("y-m-d").'.txt';
	$f=fopen($file,'a+');
	if($f){
		fwrite($f,"Connect database success: ".$user." ".gmdate('Y-m-d H:i:s')."\r");
	}
}
else {
     unset($_SESSION['username']);
	 unset($_SESSION['first_name']);
	 unset($_SESSION['last_name']);
	 unset($_SESSION['level']);
	 unset($_SESSION['account_type']);
     unset($_SESSION['partner_id']);
	 $file='../log/error/'.date("y-m-d").'.txt';
	 $f=fopen($file,'a+');
	 if($f){
		fwrite($f,"Connect database not success: ".$user." ".gmdate('Y-m-d H:i:s')."\r");
	 }
	 echo '0';
}   


?>